
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"mypushbutton.h"
#include<QAudioOutput>
#include<QUrl>
#include<QVideoWidget>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->setFixedSize(1024,648);

    this->setWindowTitle("原神min版");
    this->setWindowIcon(QIcon("://resource/tubiao.png"));

    this->startmusic=new QMediaPlayer(this);
    QAudioOutput* audiooutput=new QAudioOutput(this);
    startmusic->setAudioOutput(audiooutput);
    startmusic->setSource(QUrl("qrc:/resource/startmusic.mp3"));
    startmusic->setLoops(-1);
    startmusic->play();


    MyPushButton* startbtn=new MyPushButton("://resource/startbtn.png","://resource/startbtnpressed.png");
    startbtn->setParent(this);
    startbtn->move(720,510);

    MyPushButton* introducebtn=new MyPushButton(":/resource/introducebtn.png");
    introducebtn->setParent(this);
    introducebtn->move(630,510);

    this->playScene=new PlayScene;
    this->failedscene=new FailedScene;
    this->introducescene=new IntroduceScene;

    connect(startbtn,&QPushButton::clicked,this,[=](){
        this->hide();
        playScene->setGeometry(this->geometry());
        playScene->show();
        startmusic->pause();
        playScene->playmusic->play();
    });

    //connect(发出信号的对象，信号，接收信号的对象，槽函数）

    connect(introducebtn,&QPushButton::clicked,this,[=](){
        this->hide();
        this->introducescene->setGeometry(this->geometry());
        this->introducescene->show();
    });

    connect(this->introducescene,&IntroduceScene::back,this,[=](){
        this->introducescene->hide();
        this->setGeometry(this->introducescene->geometry());
        this->show();
    });

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load("://resource/startbackground.jpg");
    pix.scaled(1024,648);
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}


